home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 1 / ETO Development Tools 1.iso / Essentials / Developer Essentials Jul 90 / Apple II / Programming & Utilities / Apple II Getting down to Basic / NUMERIC2.TEXT.txt < prev    next >
Encoding:
Text File  |  1983-10-25  |  3.2 KB  |  227 lines

  1. %
  2. 3
  3. 7
  4. 1
  5. 38
  6. Now run the program and see if you
  7. can figure out how it works.
  8. ^
  9. %
  10. 3
  11. 7
  12. 1
  13. 38
  14. Go ahead, enter you favorite 
  15. number, 
  16. ^
  17. %
  18. 3
  19. 10
  20. 1
  21. 38
  22. The computer accepted your number
  23. and then printed it on the screen
  24. with a message.  Have you figured
  25. it out yet?  Press RETURN to see a
  26. listing of the program.
  27. ^
  28. &
  29. Here's the program.  As you may 
  30. have guessed, the INPUT statement
  31. on line 20 is the key.  The INPUT
  32. statement works like a mailman.
  33. ^
  34. &
  35. When line 20 is executed, it types
  36. a ? on the screen and waits for
  37. you to type a number.
  38. ^
  39. &
  40. Then the program delivers whatever
  41. number you type to the variable
  42. name at the end of the INPUT
  43. statement (in this case N).
  44. ^
  45. &
  46. Press RETURN for an explanation of
  47. how all the lines work together
  48. in this program.
  49. ^
  50. %
  51. 3
  52. 9
  53. 1
  54. 38
  55. (If you're thinking that this is
  56. how the computer can ask for and
  57. remember your name, you're on the
  58. right track!)
  59. ^
  60. &
  61. Up to now, we've been using
  62. NUMERIC variables--variables that
  63. store numbers.
  64. ^
  65. %
  66. 3
  67. 13
  68. 1
  69. 38
  70. Actually, there are two types of
  71. variables:
  72.  
  73. NUMERIC variables only store 
  74.        numbers.
  75.  
  76. STRING variables store strings of
  77.        characters, like names.
  78. ^
  79. %
  80. 3
  81. 10
  82. 1
  83. 38
  84. Fortunately, you don't have to be
  85. a computer genius to be able to
  86. tell one type from the other.
  87. ^
  88. &
  89. String variables have a dollar
  90. sign ($) after them.  This makes
  91. it very easy for the INPUT 
  92. "mailman" to find the right 
  93. place to store your information.
  94. ^
  95. %
  96. 3
  97. 8
  98. 1
  99. 38
  100. So, the name N signifies a numeric
  101. variable, and N$ signifies a 
  102. string variable.
  103. ^
  104. &
  105. It's time to share the secret with
  106. you. Let's look at a program that 
  107. makes use of a string variable.
  108. ^
  109. &
  110. Line 20 is an INPUT statement with
  111. a string variable (notice the $
  112. after the variable name).
  113. ^
  114. %
  115. 3
  116. 10
  117. 1
  118. 38
  119. Line 40 works the same way as the
  120. last PRINT statement worked, 
  121. except it prints a string variable
  122. instead of a numeric variable.
  123. ^
  124. &
  125. Yes, that's the secret.  It may
  126. look simple (and it is), but this
  127. is how computers ask for and
  128. remember your name!
  129. ^
  130. &
  131. Would you like to see what 
  132. this program does when it 
  133. runs? (Y/N)
  134. ^
  135. %
  136. 3
  137. 8
  138. 1
  139. 38
  140. Please erase this program from
  141. memory so that we can help you
  142. write one more program.
  143. ^
  144. %
  145. 3
  146. 8
  147. 1
  148. 38
  149. Very good!  You certainly do
  150. catch on to this computer stuff
  151. fast, 
  152. ^
  153. %
  154. 3
  155. 11
  156. 1
  157. 38
  158. OK, we've typed in a five-line
  159. program that asks for your 
  160. favorite flavor of ice cream.  But
  161. something's missing.  Do you know
  162. what it is?
  163. ^
  164. &
  165. Of course!  There's no INPUT
  166. statement on line 20.  Why don't
  167. you add the INPUT statement.  
  168. (Please use the string variable
  169. I$ since the PRINT statement on
  170. line 30 is already written.)
  171. ^
  172. %
  173. 3
  174. 8
  175. 1
  176. 38
  177. Your program is complete.  Why
  178. don't you list it so you can
  179. admire your handiwork.
  180. ^
  181. %
  182. 3
  183. 7
  184. 1
  185. 38
  186. Now try running it.
  187.  
  188. ^
  189. %
  190. 3
  191. 9
  192. 1
  193. 38
  194. Very good!  It did just what it
  195. was supposed to do.  Would you 
  196. like an explanation of how the
  197. program works? (Y/N)
  198. ^
  199. %
  200. 3
  201. 10
  202. 1
  203. 38
  204. You're well on your way to 
  205. becoming an Applesoft BASIC 
  206. programmer.
  207. ^
  208. &
  209. Of course, there is much more to
  210. learn.  You can learn how to use
  211. loops to move around inside your
  212. program and how to draw pictures
  213. on the screen.
  214. ^
  215. &
  216. Now that you understand the
  217. fundamental steps, you'll just
  218. get better the more you practice.
  219. ^
  220. &
  221. Study the Owner's Manual that
  222. came with your system for more
  223. examples of BASIC programs and
  224. some further instructions.  
  225. Good luck, and happy programming!
  226. ^
  227.